<?php
class penggunaan_beasiswa extends MY_Controller{
    var $data;
    function penggunaan_beasiswa(){
        parent::MY_Controller();
        $this->data['title'] = "Transaksi Penggunaan Beasiswa";
        $this->load->model('m_adik_asuh');
    }
    function index(){
        $this->data['content'] = "penggunaan_beasiswa/penggunaanBeasiswa";
        $this->data['listAdikAsuh'] = $this->m_adik_asuh->getAdikAsuhById($id);
        $this->data['linkBack'] = site_url('penggunaan_beasiswa');
        $this->data['titlePage'] = "Pengeluaran Adik Asuh";
        $this->data['subLink'] = "penggunaan_beasiswa/penggunaan_beasiswa_proses";
        $this->data['formTitle'] = "Form Pengeluaran Adik Asuh";
        
        $this->render($this->data);
    }
    function penggunaan_beasiswa_proses(){
        $jumlah = currencyToNumber($this->input->post('jumlah'));
        $keterangan = $this->input->post('keterangan');
        $i = 0;
        foreach ($jumlah as $jum){
            foreach ($this->m_adik_asuh->getTotalDebet($this->input->post('id_adik_asuh')) as $totalDebet);
            foreach ($this->m_adik_asuh->getTotalKredit($this->input->post('id_adik_asuh')) as $totalKredit);
            
            $data = array('tanggal' => date2mysql($this->input->post('tanggal')),
            'id_petugas' => $this->session->userdata('id_member'),
            'id_adik_asuh' => $this->input->post('id_adik_asuh'),
            'id_sekolah' => $this->input->post('id_sekolah'),
            'id_kelas' => $this->input->post('id_kelas'),
            'id_tahun_ajaran' => $this->input->post('id_tahun_ajaran'),
            'kredit' => $jum,
            'saldo' => (($totalDebet['total_debet']-$totalKredit['total_kredit'])-$jum),
            'keterangan' => $keterangan[$i]);
            
            $insert = $this->m_adik_asuh->addPengeluaranAdikAsuh($data);
            $i++;
        }
//        $insert = $this->m_adik_asuh->addPengeluaranAdikAsuh($data);
//        if($insert['status'] == TRUE){
//            $this->session->set_flashdata("message",1);
//        }else{
//            $this->session->set_flashdata("message",2);
//        }
        if($insert){
           $this->session->set_flashdata("message",1); 
        }else{
            $this->session->set_flashdata("message",2);
        }
        redirect('penggunaan_beasiswa/');
    }
    function penggunaan_beasiswa_info($id){
        $this->data['content'] = "penggunaan_beasiswa/penggunaanBeasiswaInfo";
        $this->data['linkBack'] = site_url('penggunaan_beasiswa');
        $this->data['titlePage'] = "Detail Penggunaan Beasiswa Adik Asuh";
        $this->data['formTitle'] = "Data Penggunaan Beasiswa Adik Asuh";
        $this->data['penggunaanBeasiswaAdikAsuh'] = $this->m_adik_asuh->getListPengeluaranAdikAsuh($id);
        
        $this->render($this->data);
    }
}
?>
